package com.by.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Base64;
import java.util.Enumeration;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.06.08.20.45
 */
public class AuthInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

//    Enumeration headers= request.getHeaderNames();
//    while (headers.hasMoreElements()){
//        String tmp=headers.nextElement().toString();
//        System.out.println("=========="+request.getHeader(tmp));
//    }
        String authorization=request.getHeader("authorization");
        if(null!=authorization){
            String [] header=authorization.split("\\s+");
            String rs= new String(Base64.getDecoder().decode(header[1]));
            System.out.println("认证信息"+rs);
        }
        String token=request.getHeader("x-token");
        System.out.println("token------>"+token);
        return true;
    }
}
